import request from "../utils/request";

// 获取文件磁盘空间
function getSize() {
  return request({
    url: "/dev/getsize",
    method: "GET",
  });
}

// 获取文件列表
function getFileList(fileId = 0, type = "all") {
  return request({
    url: "/dev/file",
    method: "GET",
    params: {
      file_id: fileId,
      type,
    },
  });
}

// 创建文件夹
function createDir(fileId = 0, name) {
  return request({
    url: "/dev/file/createdir",
    method: "POST",
    data: {
      file_id: fileId,
      name,
    },
  });
}

// 文件重命名
function renameFile(id, name) {
  return request({
    url: "/dev/file/rename",
    method: "POST",
    data: {
      id,
      name,
    },
  });
}

// 批量删除
function deleteFile(ids) {
  return request({
    url: "/dev/file/delete",
    method: "POST",
    data: {
      ids,
    },
  });
}

// 搜索文件
function searchFile(keyword) {
  return request({
    url: "/dev/file/search",
    method: "GET",
    params: {
      keyword,
    },
  });
}

// 下载文件
function downloadFile(url) {
  return request({
    url: url,
    method: "GET",
    responseType: "blob",
  });
}

// 分享
function shareFile(fileId) {
  return request({
    url: "/dev/share/create",
    method: "POST",
    data: {
      file_id: fileId,
    },
  });
}

export default {
  getSize,
  getFileList,
  createDir,
  renameFile,
  deleteFile,
  searchFile,
  downloadFile,
  shareFile,
};
